import UIKit

class DWSplitDownloadModel:NSObject {
    
    /// 总大小
    var totalCount : Int64 = 0
    
    /// 已下载大小
    var downloadCount : Int64 = 0
    
    /// 原始地址路径
    var originalUrl : String = ""
    
    /// 总分片数
    var splitCount : Int64 = 0
    
    /// 分片列表
    var itemList : [DWSplitDownloadItemModel] = []
    
    /// 最终文件的保存路径
    var path : String = ""
    
    /// 分片文件保存路径
    var splitPath : String = ""
    
    func saveToDic() -> [String : Any] {
        var dic : [String : Any] = [
            "totalCount":totalCount,
            "originalUrl":originalUrl,
            "splitCount":splitCount,
            "downloadCount":downloadCount,
        ]
//        var _downloadCount : Int64 = 0
        
        var itemArray : [[String : Any]] = []
        for item in itemList {
//            _downloadCount += item.downloadBytes
            itemArray.append(item.saveToDic())
        }
//        downloadCount = _downloadCount
//        dic.updateValue(downloadCount, forKey: "downloadCount")
        dic.updateValue(itemArray, forKey: "itemList")
        return dic
    }
    
}

class DWSplitDownloadItemModel: NSObject {
    
    /// 文件保存路径
    var path : String = ""
    
    /// 结束下载字节
    var endBytes : Int64 = 0
    
    /// 开始下载字节
    var beginBytes : Int64 = 0
    
    /// 当前分片编号
    var index : Int64 = 0
    
    fileprivate func saveToDic() -> [String : Any] {
        return [
            "endBytes":endBytes,
            "beginBytes":beginBytes,
            "index":index,
        ]
    }
    
}
